package com.wm.config;

import com.wm.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Map;

/**
 * @Author: weiming
 * @Date: 2021/7/16 17:02
 * @Description:
 */
@Configuration
public class ApplicationFinishListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    UserDao userDao1;

    /**
     * Handle an application event.
     *
     * @param event the event to respond to
     */
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        ApplicationContext applicationContext = event.getApplicationContext();
        Map<String, UserDao> beans = applicationContext.getBeansOfType(UserDao.class);
        UserDao userDao2 = beans.get("userDao");
        System.out.println(userDao1 == userDao2);
        System.out.println(userDao1);
        System.out.println(userDao2);
        System.out.println("ApplicationFinishListener....");
    }
}
